package de.hatraco.funderberg.blackjack.views;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import de.hatraco.funderberg.blackjack.data.DataMISC;
import de.hatraco.funderberg.blackjack.data.GraphicsBlackJack;

public class BetDialog extends JDialog {
	
	//Singleton Pattern: Stellt sicher, dass nur eine Instanz von BetDialog existiert
	private static BetDialog instance = new BetDialog();

	public static BetDialog getInstance() {
		if(instance == null) {
			instance = new BetDialog();
		}
		return instance;
	}
	
	private JLabel bg_bet;
	private JLabel bet_name;
	private JLabel bet_howmuch;
	private JLabel bet_minmax;
	private JLabel thebet;
	
	private JButton b_bet_plus1;
	private JButton b_bet_plus10;
	private JButton b_bet_plus100;
	private JButton b_bet_minus1;
	private JButton b_bet_minus10;
	private JButton b_bet_minus100;
	private JButton b_bet_max;
	private JButton b_bet_min;
	private JButton b_bet_ok;
	
	//private String link = DataMISC.LINKIMG;
	
	private GraphicsBlackJack img;
	
	private BetDialog() {
		
		//Instanziert GraphicsBlackJack (für die Bilder)
		this.img = GraphicsBlackJack.getInstance();
		
		//Legt die Größe des Fensters fest
		this.setSize(400,300);
		//Legt fest, dass die Größe nicht verändert werden kann
		this.setResizable(false);
		//Legt fest, dass das Fenster nicht über das "X" rechts oben geschlossen werden kann
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		//Gibt dem Fenster ein BorderLayout
		this.setLayout(new BorderLayout());
		//Legt den Hintergrund fest
        bg_bet = new JLabel(img.getBgdialogdef());
        //Fügt den Hintergrund hinzu
        this.add(bg_bet);
        //Gibt dem Hintergrund ein "leeres" Layout
        bg_bet.setLayout(null);
        
        //Instanziert, Modifiziert und Positioniert die Elemente
        //JLabels
        bet_name = new JLabel();
        bet_name.setFont(DataMISC.ARIAL_BOLD20);
        bet_name.setForeground(Color.WHITE);
        bet_name.setBounds(0, 10, 400, 20);
		bet_name.setHorizontalAlignment(SwingConstants.CENTER);
		
		bet_howmuch = new JLabel("Please place your bet!");
		bet_howmuch.setFont(DataMISC.ARIAL_BOLD20);
		bet_howmuch.setForeground(Color.WHITE);
		bet_howmuch.setBounds(0, 35, 400, 20);
		bet_howmuch.setHorizontalAlignment(SwingConstants.CENTER);
		
		bet_minmax = new JLabel();
		bet_minmax.setFont(DataMISC.ARIAL_BOLD20);
		bet_minmax.setForeground(Color.WHITE);
		bet_minmax.setBounds(0, 60, 400, 20);
		bet_minmax.setHorizontalAlignment(SwingConstants.CENTER);
						
		thebet = new JLabel("0");
		thebet.setFont(DataMISC.ARIAL_BOLD30);
		thebet.setForeground(Color.WHITE);
		thebet.setBounds(110, 135, 180, 50);
		thebet.setHorizontalAlignment(SwingConstants.CENTER);
		
		//Buttons
		b_bet_plus1 = new JButton(img.getBtplus1());
		b_bet_plus10 = new JButton(img.getBtplus10());
		b_bet_plus100 = new JButton(img.getBtplus100());
		b_bet_max = new JButton(img.getBtmax());
		b_bet_minus1 = new JButton(img.getBtminus1());
		b_bet_minus10 = new JButton(img.getBtminus10());
		b_bet_minus100 = new JButton(img.getBtminus100());
		b_bet_min = new JButton(img.getBtmin());
		b_bet_ok = new JButton(img.getBtok());
				
		b_bet_plus1.setBounds(50, 95, 60, 30);
		b_bet_plus10.setBounds(50, 135, 60, 30);
		b_bet_plus100.setBounds(50, 175, 60, 30);
		b_bet_max.setBounds(50, 215, 60, 30);
		b_bet_minus1.setBounds(290, 95, 60, 30);
		b_bet_minus10.setBounds(290, 135, 60, 30);
		b_bet_minus100.setBounds(290, 175, 60, 30);
		b_bet_min.setBounds(290, 215, 60, 30);
		b_bet_ok.setBounds(170, 225, 60, 40);
		
		//Fügt die Elemente dem Hintergrund hinzu
		bg_bet.add(bet_name);
		bg_bet.add(bet_howmuch);
		bg_bet.add(bet_minmax);
		bg_bet.add(b_bet_plus1);
		bg_bet.add(b_bet_plus10);
		bg_bet.add(b_bet_plus100);
		bg_bet.add(b_bet_max);
		bg_bet.add(b_bet_minus1);
		bg_bet.add(b_bet_minus10);
		bg_bet.add(b_bet_minus100);
		bg_bet.add(b_bet_min);
		bg_bet.add(b_bet_ok);
		bg_bet.add(thebet);
	}
	
	//Definiert Listener für die Buttons
	public void setBetListener(ActionListener ae) {
		this.b_bet_plus1.addActionListener(ae);
		this.b_bet_plus10.addActionListener(ae);
		this.b_bet_plus100.addActionListener(ae);
		this.b_bet_max.addActionListener(ae);
		this.b_bet_minus1.addActionListener(ae);
		this.b_bet_minus10.addActionListener(ae);
		this.b_bet_minus100.addActionListener(ae);
		this.b_bet_min.addActionListener(ae);
		this.b_bet_ok.addActionListener(ae);
	}
	
	public JLabel getBet_name() {
		return bet_name;
	}

	public void setBet_name(JLabel bet_name) {
		this.bet_name = bet_name;
	}

	public JLabel getBet_minmax() {
		return bet_minmax;
	}

	public void setBet_minmax(JLabel bet_minmax) {
		this.bet_minmax = bet_minmax;
	}

	public JLabel getThebet() {
		return thebet;
	}

	public void setThebet(JLabel thebet) {
		this.thebet = thebet;
	}

	public JButton getB_bet_plus1() {
		return b_bet_plus1;
	}

	public void setB_bet_plus1(JButton b_bet_plus1) {
		this.b_bet_plus1 = b_bet_plus1;
	}

	public JButton getB_bet_plus10() {
		return b_bet_plus10;
	}

	public void setB_bet_plus10(JButton b_bet_plus10) {
		this.b_bet_plus10 = b_bet_plus10;
	}

	public JButton getB_bet_plus100() {
		return b_bet_plus100;
	}

	public void setB_bet_plus100(JButton b_bet_plus100) {
		this.b_bet_plus100 = b_bet_plus100;
	}

	public JButton getB_bet_max() {
		return b_bet_max;
	}

	public void setB_bet_max(JButton b_bet_max) {
		this.b_bet_max = b_bet_max;
	}

	public JButton getB_bet_minus1() {
		return b_bet_minus1;
	}

	public void setB_bet_minus1(JButton b_bet_minus1) {
		this.b_bet_minus1 = b_bet_minus1;
	}

	public JButton getB_bet_minus10() {
		return b_bet_minus10;
	}

	public void setB_bet_minus10(JButton b_bet_minus10) {
		this.b_bet_minus10 = b_bet_minus10;
	}

	public JButton getB_bet_minus100() {
		return b_bet_minus100;
	}

	public void setB_bet_minus100(JButton b_bet_minus100) {
		this.b_bet_minus100 = b_bet_minus100;
	}

	public JButton getB_bet_min() {
		return b_bet_min;
	}

	public void setB_bet_min(JButton b_bet_min) {
		this.b_bet_min = b_bet_min;
	}

	public JButton getB_bet_ok() {
		return b_bet_ok;
	}

	public void setB_bet_ok(JButton b_bet_ok) {
		this.b_bet_ok = b_bet_ok;
	}
}
